package com.sunday.aomicaichang.ui.main;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;
import com.sunday.common.adapter.MainFragmentPagerAdapter;
import com.sunday.common.base.BaseFragment;
import com.sunday.common.utils.StringUtils;
import com.sunday.aomicaichang.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/5/22.
 */

public class FindFragment extends BaseFragment {

    @Bind(R.id.slide_tab)
    SlidingTabLayout slideTab;
    @Bind(R.id.view_pager)
    ViewPager viewPager;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private final String[] mTitles = {
            "菜谱秘籍", "生活常识", "选购技巧"
    };

    public static FindFragment newInstance() {
        FindFragment fragment = new FindFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_find, container, false);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        List<String> find1=new ArrayList<>();
        find1.add("fanxian_roll");
        find1.add("fanxian_cpmj");

        List<String> find2=new ArrayList<>();
        find2.add("fanxian_roll");
        find2.add("faxian_shcs");

        List<String> find3=new ArrayList<>();
        find3.add("fanxian_roll");
        find3.add("fanxian_xgjq");
        fragments.add(FindFragmentChild.newInstance(StringUtils.listToString(find1)));
        fragments.add(FindFragmentChild.newInstance(StringUtils.listToString(find2)));
        fragments.add(FindFragmentChild.newInstance(StringUtils.listToString(find3)));
        viewPager.setAdapter(new MainFragmentPagerAdapter(getChildFragmentManager(), mContext, fragments,
                R.array.buy_order_list_title));
        slideTab.setViewPager(viewPager, mTitles, getActivity(), fragments);
        viewPager.setCurrentItem(0, false);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
